package com.foreverwin.jzymes.framework.annotation;

import java.util.HashMap;
import java.util.Map;

public class MessageResultHolder {

        private static final ThreadLocal<Map<String,String>> messageResultHolder = new InheritableThreadLocal<>();

        public static void setSuccess(){
            Map<String,String> map = getMap();
            map.put( "result", "Y" );
        }

        public static void setSuccess( String message ){
            Map<String,String> map = getMap();
            map.put( "result", "Y" );
            map.put( "message", message );
        }

        public static void setError( String message ){
            Map<String,String> map = getMap();
            map.put( "result", "N" );
            map.put( "message", message );
        }

        public static String getResult(){
            Map<String,String> map = getMap();
            return map.get( "result" );
        }

        public static String getMessage(){
            Map<String,String> map = getMap();
            return map.get( "message" );
        }

        private static Map<String,String> getMap(){
            if( messageResultHolder.get() == null ){
                messageResultHolder.set( new HashMap<>() );
            }
            return messageResultHolder.get();
        }

        public static void remove(){
            messageResultHolder.remove();
        }
}
